package com.hzy.admin.services.system.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzy.admin.models.vo.system.TableVo;
import com.hzy.admin.services.system.ISysFunctionService;
import com.hzy.admin.repository.entity.system.SysFunction;
import com.hzy.admin.repository.mapper.system.ISysFunctionMapper;
import com.hzy.toolkit.Tools;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hzy
 * @since 2020-04-28
 */
@Service
public class SysFunctionServiceImpl extends ServiceImpl<ISysFunctionMapper, SysFunction> implements ISysFunctionService {
    @Override
    public TableVo<Map<String, Object>> findList(Integer page, Integer size, SysFunction search) {
        Page<Map<String, Object>> iPage = new Page<>(page, size);
        List<Map<String, Object>> data = this.baseMapper.getList(iPage, search);
        return TableVo.page(iPage, data);
    }

    @Override
    public Map<String, Object> findForm(String id) {
        Map<String, Object> map = new HashMap<>();

        SysFunction form = this.baseMapper.selectById(id);

        map.put("id", id);
        map.put("form", Tools.nullSafe(form, new SysFunction()));
        return map;
    }

    @Override
    @Transactional
    public String saveForm(SysFunction form) {
        this.saveOrUpdate(form);
        return form.getId();
    }

    @Override
    @Transactional
    public void deleteList(List<String> ids) {
        this.removeByIds(ids);

    }
}
